package com.mayikt;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @ClassName Test031
 * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com
 * @Version V1.0
 **/
public class Test031 {
    private static Lock lock = new ReentrantLock();
    private static Condition condition = lock.newCondition();

    public static void main(String[] args) throws InterruptedException {

        new Thread(() -> {
            System.out.println("1");
            try {
                lock.lock();
                //当前子线程t1会释放锁，同时变为阻塞状态。
                condition.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("2");
            lock.unlock();
        }, "t1").start();
//        // 1 3 2 312
        try {
            Thread.sleep(3000);
        } catch (Exception e) {

        }
        System.out.println("3");
        lock.lock();
        // 主线程唤醒t1
        condition.signal();
        lock.unlock();


    }
}
